package com.yunhe.merchants.task;

import com.yunhe.common.constant.TimeConsts;
import com.yunhe.common.exception.ArgumentErrorException;
import com.yunhe.common.exception.ModelNotFoundException;
import com.yunhe.common.util.StringUtil;
import com.yunhe.merchants.client.AuthorityClient;
import com.yunhe.merchants.constant.MyProjectConsts;
import com.yunhe.merchants.domain.MyProject;
import com.yunhe.merchants.service.IDataProjectService;
import com.yunhe.merchants.service.IMyProjectService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: DongWenYu
 * @Date: 2021/5/12 11:00
 */
@RestController
@EnableScheduling
public class BackScheduled {

    private static final Logger logger = LoggerFactory.getLogger(BackScheduled.class);

    @Resource(name = "myProjectServiceImpl")
    IMyProjectService myProjectService;

    @Autowired
    IDataProjectService dataProjectService;

    @Autowired
    private AuthorityClient authorityClient;

    /**
     * 每日任务两周无更新状态则自动返回商机库，并且记录历史操作记录
     *
     *           1.经理分配而来：返回经理商机库
     *
     *           2.公共商机库而来：返回公共商机库
     *
     *           3.自发：返回经理商机库
     * @return void
     * @create 2021/5/12 9:40
     */
    @Scheduled(cron = "0 0 0 0/1 *  ?")
    @RequestMapping(value = "/backHandle",method = RequestMethod.POST)
    public void handle() throws ModelNotFoundException, ArgumentErrorException {
        //开启保护期提醒
        List<MyProject> projects = myProjectService.selectNoUpdate();
//        for (MyProject p : projects) {
//            if ((System.currentTimeMillis() - p.getUpdateTime().getTime()) > 2 * TimeConsts.month) {
//                if (p.getChosenOffice() != null) {
//                    authorityClient.setOfficeStatus(p.getId(), p.getChosenOffice(), p.getCompanyName(), "01");
//                }
//                dataProjectService.backUpDateOrCreate(p);
//            }
//        }
    }
}
